<html>
<head><meta charset="utf-8"><title>Closure `Ty` into `impl FnOnce`-type syntax as string · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html">Closure `Ty` into `impl FnOnce`-type syntax as string</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220551922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220551922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220551922">(Dec 21 2020 at 04:11)</a>:</h4>
<p>Hey there! I'm working on <a href="https://github.com/rust-lang/rust/issues/80179">#80179</a> and was able to convert a function definition (e.g. <code>fn() -&gt; i32 { f }</code>) into a function pointer (the correct way, using <code>Ty::fn_sig</code>) but I'm wondering how I convert a unique closure type (as a <code>rustc_midle::ty::Ty</code>) into the <code>impl Trait</code> return type syntax for a closure, e.g. unique closure type notated as <code>[closure@&lt;anon&gt;:1:15: 1:19]</code> into <code>impl FnOnce() -&gt; i32</code>-type syntax as a <code>String</code>.</p>
<p>Does anyone know how this can be done?</p>



<a name="220551984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220551984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220551984">(Dec 21 2020 at 04:13)</a>:</h4>
<p>Alternatively, if there's a way to generically turn a <code>Ty</code> containing a function definition or a closure into valid syntax for a type, then I should probably use that.</p>



<a name="220553059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553059">(Dec 21 2020 at 04:42)</a>:</h4>
<p>rustc_middle::mir::Body?</p>



<a name="220553131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553131">(Dec 21 2020 at 04:44)</a>:</h4>
<p>I don't see how that can help me, or if I even have access to MIR at this point.</p>



<a name="220553208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553208">(Dec 21 2020 at 04:47)</a>:</h4>
<p>I thought you were looking in <code>rustc_middle</code></p>



<a name="220553254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553254">(Dec 21 2020 at 04:48)</a>:</h4>
<p>might the <code>impl Trait</code> be in the lowered representation I wonder?</p>



<a name="220553260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553260">(Dec 21 2020 at 04:49)</a>:</h4>
<p>I'm in typeck</p>



<a name="220553262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553262">(Dec 21 2020 at 04:49)</a>:</h4>
<p>I'm looking to turn a unique closure type into a string representation for a diagnostic that can be used as a valid return type for a function</p>



<a name="220553322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553322">(Dec 21 2020 at 04:51)</a>:</h4>
<p>e.g. in <code>fn f() -&gt; _ { || 5u8 }</code>; you can't have <code>_</code> as a return type so it <em>should</em> suggest to use something like <code>impl Fn() -&gt; 5u8</code> but it currently suggests <code>[closure@&lt;anon&gt;:1:15: 1:21]</code> due to a bug</p>



<a name="220553379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220553379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220553379">(Dec 21 2020 at 04:53)</a>:</h4>
<p>Unfortunately I can't just take the signature as that's <code>extern "rust-call" fn(()) -&gt; u8</code></p>



<a name="220652966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220652966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220652966">(Dec 22 2020 at 02:27)</a>:</h4>
<p>huh, it looks like <span class="user-mention" data-user-id="307537">@Camelid</span>'s post was split off into a separate thread, I'll just link my comments <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E/near/220652864">here</a></p>



<a name="220653040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as%20string/near/220653040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.20string.html#220653040">(Dec 22 2020 at 02:29)</a>:</h4>
<p>It could be your topic was too long and Zulip glitched. <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>